/*
 * @(#)HillClimbFitnessCalculator.java 1.0 16/11/13
 * 
 * Clase Compartida
 * PROP Grupo 13 Cluster 3
 */
package dominio;

import java.util.ArrayList;

/**
 * Created by Rafael Simon Garcia on 11/16/13.
 */
public class HillClimbFitnessCalculator {

    public static int Calculate(ArrayList<Integer> tour, ArrayList<? extends GraphElement> elements){
        int  i, cost = 0, length = tour.size();
        GraphElement current, next;


        //iterate over n - 1 elements of the elements ArrayList getting the cost from current to the next
        //and reducing the result to the cost variable.
        for (i=0; i < length - 1; i++){
            current = elements.get(tour.get(i));
            next = elements.get(tour.get(i + 1));
            cost += current.GetCostTo(next.id);
        }
        //magic happens with the -, because the path is decreased when looking for the smallest negative value
        return -cost;

    }
}
